package com.liuj.springbucks.mapper;

import com.liuj.springbucks.domain.Coffee;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * mapper层
 */
@Mapper
public interface CoffeeMapper {

    //分页查询列表数据
    @Select("select id,create_time as createTime,update_time as updateTime,name,price  from t_coffee order by id")
    List<Coffee> findAllWithParam(@Param("pageNum") int pageNum,
                                  @Param("pageSize") int pageSize);

    //新增咖啡信息
    @Insert("insert into t_coffee(create_time,update_time,name,price) values(#{createTime},#{updateTime},#{name},#{price})")
    @Options(useGeneratedKeys = true)
    void installCoffee(Coffee coffee);

    //修改咖啡信息
    @Update("update t_coffee set price =#{price} where id =#{id}")
    void updateCoffee(Coffee coffee);

    //删除咖啡信息
    @Delete("delete from t_coffee where id =#{id}")
    void deleteCoffee(Long id);

    //根据ID查询咖啡信息
    @Select("select * from t_coffee where id = #{id}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),
            // map-underscore-to-camel-case = true 可以实现一样的效果
            // @Result(column = "update_time", property = "updateTime"),
    })
    Coffee findById(@Param("id") Long id);

    //查询所有咖啡信息
    @Select("select id,create_time as createTime,update_time as updateTime,name,price  from t_coffee order by id")
    List<Coffee> findAll();
}
